package com.sprucetec.live.common.dto;

import java.io.Serializable;

import com.sprucetec.live.common.exceptioin.ParamInvalidException;

public class PageDTO implements Serializable {
	
	private static final long serialVersionUID = -3461554626627615367L;
	
	private int pageSize;
	private int pageIndex;
	
	public PageDTO() {
		
	}
	
	public int getSkip() {
		int skip = (this.pageIndex - 1) * this.pageSize;
		if (skip < 0) {
			return 0;
		}
		return skip;
	}

	public void checkInvalid() throws ParamInvalidException {
		if (this.pageIndex <= 0)
			throw new ParamInvalidException("pageIndex", "页码必须大于0");
		if (this.pageSize <= 0)
			throw new ParamInvalidException("pageSize", "每页条数必须大于0");
	}

	public PageDTO(int pageIndex, int pageSize) {
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
	}

	public int getPageSize() {
		return this.pageSize;
	}

	public int getPageIndex() {
		return this.pageIndex;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize; 
	}
	
	public void setPageIndex(int pageIndex) { 
		this.pageIndex = pageIndex; 
	}
	
	public String toString() { 
		return "PageDTO(pageSize=" + getPageSize() + ", pageIndex=" + getPageIndex() + ")";
	}
	
}
